package com.pfzy.lib.sdk.log;

import java.io.File;
import java.io.FileFilter;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Locale;

/**
 * 日索引文件筛选器
 */
public class UXLogDayIndexFileFilter implements FileFilter {
    private int dayIndex;

    public UXLogDayIndexFileFilter(int dayIndex) {
        this.dayIndex = 0;
        this.dayIndex = dayIndex;
    }

    @Override
    public boolean accept(File file) {
        boolean isFile = file.isFile();
        boolean isXlog = file.getName().endsWith(".xlog");
        SimpleDateFormat yyyyMMddFormat = new SimpleDateFormat("yyyyMMdd");
        boolean isDayIndex = file.getName().indexOf(yyyyMMddFormat.format(Calendar.getInstance(Locale.getDefault()).getTimeInMillis() - (((long) this.dayIndex) * 86400000))) > 0;
        return isFile && isXlog && isDayIndex;
    }
}
